﻿<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>达内－NetCTOSS</title>
        <link type="text/css" rel="stylesheet" media="all" href="/netctoss/styles/global.css" />
        <link type="text/css" rel="stylesheet" media="all" href="/netctoss/styles/global_color.css" /> 
  		<script type="text/javascript" src="/netctoss/js/jquery-1.11.1.js">
  		</script>
    	<script type="text/javascript">
    		function doSubmit(){
    			
    			//提交表单
    			var name = $("#admin_code").val();
    			var pwd = $("#password").val();
    			var code = $("#code").val();
    			//TODO 格式检查
    			//发送请求
    			$.ajax({
    				url:"/netctoss/login/login/"+code,
    				type:"get",
    				beforeSend:function(xhr){
    					//将账号和密码放入HTTP请求的Header部分
    					xhr.setRequestHeader("name",name);
    					xhr.setRequestHeader("password",pwd);
    				},
    				success:function(data){//data是服务器返回内容
    					//TODO
    					var ok = data.login;
    					if(ok){//登录成功,进入index.jsp
    						window.location="/netctoss/login/toIndex";
    					}else{
    						//登录未成功,将返回的错误信息显示
    						$("#code_error").html(data.code_error);
    						$("#error").html(data.error);
    						//刷新验证码信息
    						$("#codeImg").attr("src","/netctoss/login/getCode");
    					}
    				}
    			});
    			
    		}
    	</script>
    
    </head>
    <body class="index">
    	<form id="loginForm">
        <div class="login_box">
            <table>
                <tr>
                    <td class="login_info">账号：</td>
                    <td colspan="2"><input name="admin_code" id="admin_code" type="text" class="width150" /></td>
                    <td class="login_error_info"><span class="required">30长度的字母、数字和下划线</span></td>
                </tr>
                <tr>
                    <td class="login_info">密码：</td>
                    <td colspan="2"><input name="password" id="password" type="password" class="width150" /></td>
                    <td><span class="required">30长度的字母、数字和下划线</span></td>
                </tr>
                <tr>
                    <td class="login_info">验证码：</td>
                    <td class="width70"><input name="code" id="code" type="text" class="width70" /></td>
                    <td><img id="codeImg" src="getCode" alt="验证码" title="点击更换" /></td>  
                    <td><span id="code_error" class="required"></span></td>              
                </tr>            
                <tr>
                    <td></td>
                    <td class="login_button" colspan="2">
                        <a href="javascript:;" onclick="doSubmit();">
                        <img src="../images/login_btn.png" /></a>
                    </td>    
                    <td><span id="error" class="required"></span></td>                
                </tr>
            </table>
        </div>
        </form>
    </body>
</html>
